<?php  namespace Admin\Controller;

class BrandController extends CommonController{
	
	private $model;
	
	public function __construct(){
		parent::__construct();
		$this->model = new \Common\Model\Brand;
	}
	
	public function addBrand(){
		if(IS_POST){
			if($this->model->addData())View::success('添加成功',U('index'));
			View::error($this->model->getError());
		}
		View::make();
	}
	
	
	public function editBrand(){
		if(IS_POST){
			if($this->model->editData())View::success('编辑成功',U('index'));
			View::error($this->model->getError());
		}
		$bid = Q('get.bid',0,'intval');
		$oldBrandData = $this->model->where("bid={$bid}")->find();
		View::with('data',$oldBrandData);
		View::make();
	}
	
	public function delBrand(){
		$bid = Q('get.bid',0,'intval');
		$this->model->where("bid={$bid}")->delete();
		View::success("删除成功",U('index'));
	}
	public function index(){
		$brandData = $this->model->orderBy('bsort')->get();
		View::with('brandData',$brandData);
		View::make();
	}
	
	public function updatesort(){
		$data=(Q('post.'));
		$newdata  = array();
		foreach ($data['sort'] as $k => $v) {
			$newdata []= array(
			  "bsort"=>$v,
			  'bid'=>$data['bid'][$k],
			);
		}
		foreach ($newdata as $k => $v) {
			$this->model->where("bid={$v['bid']}")->update(array('bsort'=>$v['bsort']));
		}
		go(U('index'));
	}
}


 ?>